/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sqlserver;

import java.awt.BorderLayout;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author ROMANCE
 */

public class ServerInitiator {
    private JFrame frame = new JFrame();
    private JDesktopPane desktop = new JDesktopPane();

    public static void main(String args[]){
        String port = JOptionPane.showInputDialog("Nhập vào port: ");
        new ServerInitiator().initialize(Integer.parseInt(port));
    }

    public void initialize(int port){
        try {
            ServerSocket sc = new ServerSocket(port);
            drawGUI();
            while(true){
                Socket client = sc.accept();
                System.out.println("Có một client đã kết nối tới!");
                //new ClientHandler(client,desktop);
            }
        } catch (IOException ex) {
        }
    }
    
    public void drawGUI(){
        frame.add(desktop,BorderLayout.CENTER);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setExtendedState(frame.getExtendedState()|JFrame.MAXIMIZED_BOTH);
        frame.setVisible(true);
    }
}
